namespace WP7Contrib.Services.BingMaps.Model
{
    using Collections;
    using Common;
    using Common.Extensions;

    public class LocationSearchResult : Result, ICloneable<LocationSearchResult>
    {
        private ObservableCollection<LocationData> locations;

        public LocationSearchResult()
            : base()
        {
            this.locations = new ObservableCollection<LocationData>();
        }

        public ObservableCollection<LocationData> Locations
        {
            get
            {
                return this.locations;
            }
            set
            {
                this.SetPropertyAndNotify(ref locations, value, () => Locations);
            }
        }

        public bool HasLocations
        {
            get { return this.locations != null && this.locations.Count != 0; }
        }

        public LocationSearchResult ShallowClone()
        {
            var result = new LocationSearchResult
            {
                Locations = this.locations
            };

            result.CloneBaseResult(this);
            return result;
        }

        public LocationSearchResult DeepClone()
        {
            var copy = new ObservableCollection<LocationData>();
            
            if (this.HasLocations)
                this.locations.ForEach(i => copy.Add(i.DeepClone()));

            var result = new LocationSearchResult
            {
                Locations = copy,
            };

            result.CloneBaseResult(this);
            return result;
        }
    }
}